#ifndef NETWORKCAPTURETHREAD_H
#define NETWORKCAPTURETHREAD_H

#include <QThread>
#include <QString>

#include <pcap.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>

#include "arp.h"
#include "icmp.h"
#include "ip.h"


class NetworkCaptureThread : public QThread
{
public:
    NetworkCaptureThread();
    void run();
    ~NetworkCaptureThread();

private:
//    void *ThreadDisplayPkt();
    static void EthernetPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);
    static void IpPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);
    static void ArpPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);
    void TcpPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);
    void UdpPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);
    static void IcmpPktCallback(u_char *argument, const struct pcap_pkthdr *packet, const u_char *packet_content);

    typedef struct{
        u_char *argument;
        struct pcap_pkthdr *header;
        u_char *pktdata;
    }sfunc, *psfunc;

    int ret;
    char *dev;  // 设备
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t *descr;
    pcap_dumper_t *fileInfo;
//    char filter_exp[10 * PCAP_ERRBUF_SIZE];

    struct bpf_program fp;
    bpf_u_int32 netp;
    bpf_u_int32 maskp;

};

#endif // NETWORKCAPTURETHREAD_H
